import * as api from "@/request/api";

export default {
  namespaced: true, // 为每个模块添加一个前缀
  state: {
    token: localStorage.getItem("token") || null,
    account:{},
  },
  mutations: {
    logOut: (state) => {
      //退出登录
      state.account = {};
      state.token = null;
      localStorage.removeItem("token");
      localStorage.removeItem("account");
    },
    upToken: (state, token) => {
      //用户Token更新
      state.token = token;
      localStorage.setItem("token", token);
    },
    upAccount: (state, account) => {
      //更新用户信息
      state.account = account;
      // localStorage.setItem("account", JSON.stringify(account));
    },
  },
  actions: {
    async setAccount({ commit }) {
      let res = await api.userInfo();
      commit("upAccount", res.data);
    },
  },
};
